package com.fuerda.izb.utils

import android.content.Context
import android.view.Gravity
import android.widget.Toast
import com.fuerda.izb.MainApplication

object ToastUtil {
    private const val TAG = "IToastUtils"
    fun showToast(resId: String) {
        showToast(MainApplication.instance(), resId)
    }

    fun showToast(context: Context?, msg: String?) {
        var mToast: Toast? = null
        try {
            if (context == null) {
                return
            }
            if (mToast == null) {
                synchronized(ToastUtil::class.java) {
                        mToast = Toast.makeText(context, msg, Toast.LENGTH_SHORT)
                }
            } else {
                mToast!!.setText(msg)
                mToast!!.duration = Toast.LENGTH_SHORT
            }
            mToast!!.setGravity(Gravity.CENTER, 0, 0)
            mToast!!.show()
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }
}